//package com.thinksns.sociax.t4.android.fragment;
//
//import android.content.Context;
//import android.graphics.drawable.ColorDrawable;
//import android.os.Bundle;
//import android.text.Editable;
//import android.text.TextUtils;
//import android.text.TextWatcher;
//import android.view.LayoutInflater;
//import android.view.MotionEvent;
//import android.view.View;
//import android.webkit.WebView;
//import android.widget.AdapterView;
//import android.widget.Button;
//import android.widget.EditText;
//import android.widget.ImageView;
//import android.widget.ListView;
//
//import com.scwang.smartrefresh.layout.SmartRefreshLayout;
//import com.scwang.smartrefresh.layout.api.RefreshLayout;
//import com.scwang.smartrefresh.layout.listener.OnLoadmoreListener;
//import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
//import com.thinksns.sociax.android.R;
//import com.thinksns.sociax.t4.adapter.AdapterCommentList;
//import com.thinksns.sociax.t4.adapter.AdapterSociaxList;
//import com.thinksns.sociax.t4.android.Listener.onWebViewLoadListener;
//import com.thinksns.sociax.t4.android.Thinksns;
//import com.thinksns.sociax.t4.android.activity.InformationDetailsActivity;
//import com.thinksns.sociax.t4.android.interfaces.InformationDetailsListener;
//import com.thinksns.sociax.t4.android.popupwindow.PopupWindowListDialog;
//import com.thinksns.sociax.t4.android.presenter.InformationPresenter;
//import com.thinksns.sociax.t4.android.video.ToastUtils;
//import com.thinksns.sociax.t4.model.ModelBackMessage;
//import com.thinksns.sociax.t4.model.ModelComment;
//import com.thinksns.sociax.t4.model.ModelInformationCateList;
//import com.thinksns.sociax.t4.unit.UnitSociax;
//import com.thinksns.sociax.thinksnsbase.activity.widget.EmptyLayout;
//import com.thinksns.sociax.thinksnsbase.activity.widget.ListFaceView;
//import com.thinksns.sociax.thinksnsbase.bean.ListData;
//import com.thinksns.sociax.thinksnsbase.bean.SociaxItem;
//import com.thinksns.sociax.unit.SociaxUIUtils;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import static com.thinksns.sociax.api.Api.Status.SUCCESS;
//
//
///**
// * @author LeiYan
// * @describe 资讯详情页 需传入 id：资讯 id
// * @date 2017/2/5
// * @contact email:907238552@qq.com
// */
//
//public class InformationDetailsFragment extends FragmentSociax implements OnRefreshListener,OnLoadmoreListener, InformationDetailsListener {
//    private static InformationDetailsFragment mInstance;
//
//    private SmartRefreshLayout smartRefreshLayout;
//    private ImageView mFaceIv;
//    private EditText mCommentEt;
//    private Button mSendBtn;
//    private ListFaceView mFaceView;
//    private EmptyLayout mEmptyLayout;
//    private View headView;
//    private WebView mWVContent;
//    private int mInformationId;
//    private ModelInformationCateList mCateDetail;
//    private InformationPresenter mPresenter;
//    private ModelComment mReplyComment;
//    PopupWindowListDialog.Builder mCommentBuilder = null;
//    private ModelComment fromComment; //5.23 zhouhao 新加字段, 从回复页的评论跳转至此
//    private boolean isFirstComeWithComment = true;
//    public boolean isDatasLoaded = false;
//    private InformationDetailsActivity mActivity;
//    private UnitSociax mUnitSociax;
//
//    public ModelInformationCateList getCateDetail() {
//        return mCateDetail;
//    }
//
//    public static InformationDetailsFragment getInstance(Bundle bundle) {
//        mInstance = new InformationDetailsFragment();
//        mInstance.setArguments(bundle);
//        return mInstance;
//    }
//
//    @Override
//    public int getLayoutId() {
//        return R.layout.fragment_information_details;
//    }
//
//    @Override
//    public void initView() {
//        // 设置下拉刷新组件
//        smartRefreshLayout = (SmartRefreshLayout)findViewById(R.id.smart_refresh_layout);
//        mFaceIv = (ImageView) findViewById(R.id.img_face);
//        mCommentEt = (EditText) findViewById(R.id.et_comment);
//        mSendBtn = (Button) findViewById(R.id.btn_send_comment);
//        mFaceView = (ListFaceView) findViewById(R.id.face_view);
//        mEmptyLayout = (EmptyLayout) findViewById(R.id.empty_layout);
//        mFaceView.initSmileView(mCommentEt);
//        smartRefreshLayout.setOnRefreshListener(this);
//        smartRefreshLayout.setOnLoadmoreListener(this);
//        smartRefreshLayout.setEnableRefresh(true);
//        smartRefreshLayout.setEnableLoadmore(true);// 设置列表样式
//        listView = (ListView) findViewById(R.id.pull_refresh_list);
//        listView.setDividerHeight(UnitSociax.dip2px(getActivity(), 0.5f));
//        listView.setDivider(new ColorDrawable(getResources().getColor(R.color.bg_listview_divider)));
//        headView = LayoutInflater.from(getActivity()).inflate(R.layout.header_infomation_details, null);
//        listView.addHeaderView(headView);
//        mWVContent = (WebView) headView.findViewById(R.id.wv_content);
//
//        adapter = createAdapter();
//        listView.setAdapter(adapter);
//        ((AdapterCommentList) adapter).setType("information");
//        mEmptyLayout.setErrorType(EmptyLayout.NETWORK_LOADING);
//        mUnitSociax = new UnitSociax(getActivity());
//        adapter.setOnLoadListener(new AdapterSociaxList.OnLoadListener() {
//            @Override
//            public void onLoadcomplete() {
//                smartRefreshLayout.finishLoadmore();
//                smartRefreshLayout.finishRefresh();
//            }
//        });
//    }
//
//    @Override
//    public void onAttach(Context context) {
//        super.onAttach(context);
//        if (context instanceof InformationDetailsActivity) {
//            mActivity = (InformationDetailsActivity) context;
//        }
//    }
//
//    @Override
//    public void onDestroy() {
//        super.onDestroy();
//    }
//
//    @Override
//    public void initIntentData() {
//        mInformationId = getArguments().getInt("id");
//        fromComment = (ModelComment) getArguments().getSerializable("comment");
//    }
//
//    @Override
//    public void initListener() {
//        mEmptyLayout.setOnLayoutClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mPresenter.loadDetails();
//            }
//        });
//        mFaceIv.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (mFaceView.getVisibility() == View.VISIBLE) {
//                    mFaceView.setVisibility(View.GONE);
//                    UnitSociax.showSoftKeyborad(v.getContext(), mCommentEt);
//                    mFaceIv.setImageResource(R.drawable.face_bar);
//                } else {
//                    mFaceView.setVisibility(View.VISIBLE);
//                    UnitSociax.hideSoftKeyboard(v.getContext(), mCommentEt);
//                    mFaceIv.setImageResource(R.drawable.key_bar);
//                }
//            }
//        });
//        mSendBtn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (TextUtils.isEmpty(mCommentEt.getText())) {
//                    return;
//                } else if (mCommentEt.length() > 140) {
////                    ToastUtils.showToast(R.string.tip_comment_count_over_140);
//                    return;
//                }
//                v.setEnabled(false);
//                sendComment();
//            }
//        });
//        mCommentEt.addTextChangedListener(new TextWatcher() {
//            @Override
//            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//
//            }
//
//            @Override
//            public void onTextChanged(CharSequence s, int start, int before, int count) {
//
//            }
//
//            @Override
//            public void afterTextChanged(Editable s) {
//                if (TextUtils.isEmpty(mCommentEt.getText())) {
//                    mSendBtn.setBackgroundResource(R.drawable.roundbackground_gray_chat_item);
//                } else {
//                    mSendBtn.setBackgroundResource(R.drawable.roundbackground_blue_chat_item);
//                }
//            }
//        });
//        mCommentEt.setOnTouchListener(new View.OnTouchListener() {
//            @Override
//            public boolean onTouch(View v, MotionEvent event) {
//                if (!mCateDetail.isCan_comment()) {
//                    ToastUtils.showToast(R.string.tip_no_oauth_to_comment_weibo);
//                    return true;
//                }
//                if (mFaceView.getVisibility() == View.VISIBLE) {
//                    mFaceView.setVisibility(View.GONE);
//                    mFaceIv.setImageResource(R.drawable.face_bar);
//                    UnitSociax.showSoftKeyborad(v.getContext(), mCommentEt);
//                }
//                return false;
//            }
//        });
//        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                if (id >= 0) {
//                    if (!mCateDetail.isCan_comment()) {
//                        ToastUtils.showToast(R.string.tip_no_oauth_to_comment_weibo);
//                        return;
//                    }
//
//                    final ModelComment comment = (ModelComment) adapter.getItem((int) id);
//                    if (Integer.parseInt(comment.getUid()) == Thinksns.getMy().getUid()) {
//                        /*我的评论*/
//                        mReplyComment = null;
//                        getItemOptions(comment);
//                    } else {
//                        if (mCateDetail.getAuthor() != Thinksns.getMy().getUid() && !mCateDetail.isCan_comment()) {
//                            ToastUtils.showToast(R.string.tip_no_oauth_to_comment_post);
//                            return;
//                        } else {
//                            mReplyComment = comment;
//                            setCommentUseful();
//                        }
//                    }
//
//                }
//            }
//        });
//        listView.setOnTouchListener(new View.OnTouchListener() {
//
//            @Override
//            public boolean onTouch(View v, MotionEvent event) {
//                resetCommentUI();
//                return false;
//            }
//
//        });
//    }
//
//    /**
//     * // 获取菜单选项 ,自己的评论删除
//     *
//     * @param comment
//     */
//    private void getItemOptions(ModelComment comment) {
//        final boolean isMy = Integer.parseInt(comment.getUid()) == Thinksns.getMy().getUid();
//        mReplyComment = comment;
//        List<String> datas = new ArrayList<String>();
//        if (isMy) {
//            datas.add(getString(R.string.delete));
//            datas.add(getString(R.string.cancel));
//            createOptionsMenu(datas, comment);
//        } else {
//            setCommentUseful();
////            datas.add(getStrings(R.string.comment));
//        }
////        datas.add(getStrings(R.string.copy));
//    }
//
//    // 创建菜单项
//    private void createOptionsMenu(List<String> datas, final ModelComment comment) {
//        mCommentBuilder = new PopupWindowListDialog.Builder(getActivity());
//
//        mCommentBuilder.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                mCommentBuilder.dimss();
//                if (position == 0) {
//                    if (Integer.parseInt(mReplyComment.getUid()) == Thinksns.getMy().getUid()) {
//                        // 删除评论
//                        deleteComment(comment);
//                    }
//                } else if (position == 1) {
//                    mCommentBuilder.dimss();
//                    // 复制评论
////                    UnitSociax.copy(mReplyComment.getContent(),getActivity());
//                }
//
//            }
//        });
//
//        mCommentBuilder.create(datas);
//    }
//
//    /**
//     * 删除评论
//     *
//     * @param comment
//     */
//    private void deleteComment(ModelComment comment) {
//        mPresenter.deleteComment(comment);
//    }
//
//    @Override
//    public void initData() {
//        if (mPresenter == null) {
//            mPresenter = new InformationPresenter(getActivity(), mInformationId, this);
//        }
//        mPresenter.loadDetails();
//    }
//
//    @Override
//    public AdapterSociaxList createAdapter() {
//        return new AdapterCommentList(this, list, mInformationId);
//    }
//
//    @Override
//    public void executeDataSuccess(ListData<SociaxItem> list) {
//        super.executeDataSuccess(list);
//        if (list.size() < 10) {
//            smartRefreshLayout.setEnableLoadmore(false);
//            smartRefreshLayout.setEnableRefresh(true);
//        } else if (list.size() >= 10) {
//            smartRefreshLayout.setEnableLoadmore(true);
//            smartRefreshLayout.setEnableRefresh(true);
//        }
//    }
//
//    public void setHeadContent(ModelInformationCateList informationDetails) {
////        String h5Content = AppendPost.WEB_STYLE + informationDetails.getContent();
//        // 设置setWebChromeClient对象
////        mUnitSociax.appendWebViewContent(mWVContent, h5Content, new onWebViewLoadListener() {
////            @Override
////            public void onPageStarted() {
////                mEmptyLayout.setErrorType(EmptyLayout.NETWORK_LOADING);
////            }
////
////            @Override
////            public void onPageFinished() {
////                mEmptyLayout.setErrorType(EmptyLayout.HIDE_LAYOUT);
////            }
////        });
//    }
//
//    /**
//     * 获取详情成功回调
//     *
//     * @param cateList
//     */
//    @Override
//    public void loadDetailsSuccess(ModelInformationCateList cateList) {
//        /*分享弹窗显示时，点击刷新提示刷新成功*/
//        if (mActivity != null && mActivity.isShowMorePopupWindow()) {
//            ToastUtils.showToast(R.string.refresh_success);
//        }
//        smartRefreshLayout.finishLoadmore();
//        smartRefreshLayout.finishRefresh();
//        mCateDetail = cateList;
//        setHeadContent(cateList);//?linsr 2017年11月09日23:47:00
//        ((AdapterCommentList) adapter).setFeedId(mCateDetail.getId());
//        list = new ListData<SociaxItem>();
//        list.addAll(mCateDetail.getComment_info());
//        ((AdapterCommentList) adapter).setData(list);
//        executeDataSuccess(list);
//        isDatasLoaded = true;
//        ((InformationDetailsActivity) getActivity()).setTitle(cateList.getSubject());
//        /*when come by comment me,show comment view for is comment*/
//        if (fromComment != null && isFirstComeWithComment) {
//            isFirstComeWithComment = false;
//            if (!mCateDetail.isCan_comment()) {
//                ToastUtils.showToast(R.string.you_have_no_pority);
//            } else {
//                mReplyComment = fromComment;
//                setCommentUseful();
//            }
//        }
//    }
//
//    /**
//     * 获取详情失败回调
//     *
//     * @param result
//     */
//    @Override
//    public void loadDetailsFailure(Object result) {
//        smartRefreshLayout.finishLoadmore();
//        smartRefreshLayout.finishRefresh();
//        if (mCateDetail == null) {
//            mEmptyLayout.setErrorType(EmptyLayout.NETWORK_ERROR);
//        } else if (!TextUtils.isEmpty(String.valueOf(result))) {
//            ToastUtils.showToast(String.valueOf(result));
//        }
//    }
//
//    @Override
//    public void sendCommentResult(ModelBackMessage msg, ModelComment replyComment) {
//        mSendBtn.setEnabled(true);
//        ToastUtils.showToast(msg.getMsg());
//        if (msg.getStatus() == SUCCESS.ordinal()) {
//            resetCommentUI();
//            replyComment.setUid(String.valueOf(Thinksns.getMy().getUid()));
//            replyComment.setComment_id(!TextUtils.isEmpty(msg.getCid()) ? Integer.parseInt(msg.getCid()) : 1);
//            replyComment.setCtime(String.valueOf(System.currentTimeMillis() / 1000));
//            ((AdapterCommentList) adapter).addItem(0, replyComment);
//        }
//    }
//
//    /**
//     * 删除评论成功
//     *
//     * @param comment
//     */
//    @Override
//    public void deleteCommentSuccess(ModelComment comment) {
//        ((AdapterCommentList) adapter).removeItem(comment);
//        mCateDetail.setComment_count(mCateDetail.getComment_count() - 1);
//
//    }
//
//    private void sendComment() {
//        ModelComment comment = new ModelComment();
//        comment.setUface(String.valueOf(Thinksns.getMy().getUserface()));
//        comment.setUname(Thinksns.getMy().getUserName());
//        String content = String.valueOf(mCommentEt.getText()).trim();
//        String realContent = content;
//        if (mReplyComment != null && !String.valueOf(Thinksns.getMy().getUid()).equals(mReplyComment.getUid())) {
//            comment.setReplyCommentId(mReplyComment.getComment_id());
//            comment.setTo_uid(Integer.parseInt(mReplyComment.getUid()));
//            comment.setUid(mReplyComment.getUid());
//            realContent = getString(R.string.replyat) + (TextUtils.isEmpty(mReplyComment.getRemark()) ? mReplyComment.getUname() : mReplyComment.getRemark()) + "：" + content;
//            content = String.format(getResources().getString(R.string.format_reply_comment), mReplyComment.getUname(), content);
//        }
//        comment.setContent(content);
//        mPresenter.addComment(comment, realContent);
//    }
//
//    private void setCommentUseful() {
//        setCommentUseful(mReplyComment);
//    }
//
//    private void setCommentUseful(ModelComment comment) {
//        if (comment != null && !String.valueOf(Thinksns.getMy().getUid()).equals(comment.getUid())) {
//            if (!TextUtils.isEmpty(comment.getRemark())) {
//                mCommentEt.setHint(getString(R.string.reply) + " " + comment.getRemark() + ":");
//            } else {
//                mCommentEt.setHint(getString(R.string.reply) + " " + comment.getUname() + ":");
//            }
//        }
//        mCommentEt.requestFocus();
//        mCommentEt.setText("");
//        //延迟显示输入法键盘
//        mCommentEt.postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                SociaxUIUtils.showSoftKeyborad(getActivity(), mCommentEt);
//            }
//        }, 100);
//    }
//
//    private void resetCommentUI() {
//        mCommentEt.clearFocus();
//        // 保留编辑框的输入内容
//        mCommentEt.setHint(getResources().getString(R.string.comment_hint_edit));
//        mCommentEt.setText("");
//        SociaxUIUtils.hideSoftKeyboard(getActivity(), mCommentEt);
//        mReplyComment = null;
//    }
//
//    public ModelInformationCateList getInformationDetails() {
//        return mCateDetail;
//    }
//
//    @Override
//    public void onLoadmore(RefreshLayout refreshlayout) {
//        adapter.doRefreshFooter();
//    }
//
//    @Override
//    public void onRefresh(RefreshLayout refreshlayout) {
//        mPresenter.loadDetails();
//    }
//}
